package com.laikan.reader.bookfriend.activity;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.laikan.library.components.activitys.BasicActivity;
import com.laikan.reader.R;
import com.laikan.reader.core.LaikanBaseAdapter;
import com.laikan.reader.core.utils.PublicUtil;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * 阅读券说明界面
 *
 * @author Administrator
 */
public class ReadTicketIntroduceActivity extends BasicActivity {

    private ListView lv_coupon_des;
    private String[] mData;
    private CouponInfoAdapter mAdapter;
    private ImageView back_tv;
    private RelativeLayout back_layout;
    Drawable drawable_back_tv;

    @Override
    protected void assignViews() {
        setContentView(R.layout.lk_coupon_info);
        back_tv = (ImageView)findViewById(R.id.iv_back);
        back_layout = (RelativeLayout)findViewById(R.id.back_layout);
        lv_coupon_des = (ListView)findViewById(R.id.lv_coupon_des);
    }

    @Override
    protected void initData() {
        drawable_back_tv = new BitmapDrawable(PublicUtil.getAlphaBitmap(PublicUtil.readBitMap(mContext, R.drawable.lk_back_small), Color.parseColor("#66ccdd")));
        back_tv.setImageDrawable(drawable_back_tv);
        mData = getResources().getStringArray(R.array.couponInfo);
        mAdapter = new CouponInfoAdapter(mContext);
        mAdapter.setDatas(new ArrayList<String>(Arrays.asList(mData)));
        lv_coupon_des.setAdapter(mAdapter);
    }

    @Override
    protected void setListener() {
        back_layout.setOnClickListener(this);
    }

    @Override
    protected void onClickEvent(View view) {
        switch (view.getId()){
            case R.id.back_layout:
                finish();
                break;
            default:
                break;
        }
    }

    class CouponInfoAdapter extends LaikanBaseAdapter<String> {

        public CouponInfoAdapter(Context mContext) {
            super(mContext);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup arg2) {
            ViewHolder holder = null;
            if (convertView == null) {
                // 获取控件
                holder = new ViewHolder();
                convertView = View.inflate(mContext, R.layout.lk_coupon_info_item, null);
                holder.tv_des = (TextView)convertView.findViewById(R.id.tv_des);
                convertView.setTag(holder);
            }else {
                holder = (ViewHolder)convertView.getTag();
            }
            if (position % 2 == 0) {
                holder.tv_des.setBackgroundColor(getResources().getColor(R.color.C_F1F1F1));
            }else {
                holder.tv_des.setBackgroundColor(getResources().getColor(R.color.C_FFFFFF));
            }
            holder.tv_des.setText(datas.get(position));
            return convertView;
        }

        private class ViewHolder {

            private TextView tv_des;
        }

    }

}
